﻿// Picturez
//
// Copyright © Frank Nagl, 2008-2012
// admin@franknagl.de
// www.franknagl.de
//
namespace Picturez
{
    using System;
    using System.Windows.Forms;

    partial class MainForm
    {
        private void ChangePathKryptonButtonClick(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            const int nr = 80;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Current.Path = dialog.SelectedPath;
                if (Current.Path.Length > nr)
                {
                    int start = Current.Path.Length - nr + 3;
                    OutputPathKryptonLabel.Text =
                        "..." + Current.Path.Substring(start);
                }
                else
                    OutputPathKryptonLabel.Text = Current.Path;
            }
        }

        private void ConvertKryptonButtonClick(object sender, EventArgs e)
        {
            //When no output path is selected --> return
            if (Current.Path == "" && !Current.UseOriginalPath)
            {
                MessageBoxOk.Show(language.Text[14]);
                OutputPathKryptonLabel.Text = language.Text[14];
                return;
            }

            ProgressBar bar = ProgressForm.InitFormAndProgressBar(language.Text[16],
                Icon, 0, images.Count, 1);
            if (Current.UseOriginalPath)
            {
                if (OriginalSizeKryptonRadioButton.Checked)
                    for (int i = 0; i < images.Count; i++)
                    {
                        ImageConverter.ConvertTo(
                            Current.DotnetImageFormat,
                            images[i],
                            Current.FileOverwriting,
                            Current.JpgQuality,
                            Current.HighQuality);
                        bar.PerformStep();
                    }
                else if (BiggestLengthKryptonRadioButton.Checked)
                    for (int i = 0; i < images.Count; i++)
                    {
                        ImageConverter.ConvertTo(
                            Current.DotnetImageFormat,
                            images[i],
                            Current.FileOverwriting,
                            Current.JpgQuality,
                            Current.BiggestLength,
                            Current.HighQuality);
                        bar.PerformStep();
                    }
                else
                    for (int i = 0; i < images.Count; i++)
                        ImageConverter.ConvertTo(
                            Current.DotnetImageFormat,
                            images[i],
                            Current.FileOverwriting,
                            Current.JpgQuality,
                            Current.Width,
                            Current.Height,
                            !Current.StretchImage,
                            Current.HighQuality);
            }
            else
            {
                if (OriginalSizeKryptonRadioButton.Checked)
                    for (int i = 0; i < images.Count; i++)
                    {
                        ImageConverter.ConvertTo(
                            Current.DotnetImageFormat,
                            images[i],
                            Current.Path + "\\" + ImagesKryptonListBox.Items[i],
                            Current.JpgQuality,
                            Current.FileOverwriting,
                            Current.HighQuality);
                        bar.PerformStep();
                    }

                else if (BiggestLengthKryptonRadioButton.Checked)
                    for (int i = 0; i < images.Count; i++)
                    {
                        ImageConverter.ConvertTo(
                            Current.DotnetImageFormat,
                            images[i],
                            Current.Path + "\\" + ImagesKryptonListBox.Items[i],
                            Current.JpgQuality,
                            Current.BiggestLength,
                            Current.FileOverwriting,
                            Current.HighQuality);
                        bar.PerformStep();
                    }

                else
                    for (int i = 0; i < images.Count; i++)
                    {
                        ImageConverter.ConvertTo(
                            Current.DotnetImageFormat,
                            images[i],
                            Current.Path + "\\" + ImagesKryptonListBox.Items[i],
                            Current.JpgQuality,
                            Current.Width,
                            Current.Height,
                            !Current.StretchImage,
                            Current.FileOverwriting,
                            Current.HighQuality);
                        bar.PerformStep();
                    }
            }

            if (MessageBoxOk.Show(language.Text[17]) == DialogResult.OK)
                bar.Parent.Dispose();
        }        
    }
}
